<template>
  <div id="app">
    <el-container>
      <!-- 头部导航 -->
      <el-header class="header">
        <div class="header-content">
          <div class="logo">
            <h2>🎰 转盘抽奖系统</h2>
          </div>
          <div class="nav-menu">
            <el-menu
              :default-active="$route.path"
              mode="horizontal"
              router
              background-color="transparent"
              text-color="#fff"
              active-text-color="#ffd04b"
            >
              <el-menu-item index="/">首页</el-menu-item>
              <el-menu-item index="/lottery">抽奖</el-menu-item>
              <el-menu-item index="/records">记录</el-menu-item>
              <el-menu-item v-if="userStore.isAdmin" index="/admin">管理</el-menu-item>
            </el-menu>
          </div>
          <div class="user-info">
            <div v-if="userStore.isLoggedIn" class="user-actions">
              <span class="username">{{ userStore.user.username }}</span>
              <el-button type="primary" @click="logout">退出</el-button>
            </div>
            <div v-else class="auth-buttons">
              <el-button type="primary" @click="$router.push('/login')">登录</el-button>
              <el-button @click="$router.push('/register')">注册</el-button>
            </div>
          </div>
        </div>
      </el-header>

      <!-- 主要内容区域 -->
      <el-main class="main-content">
        <router-view />
      </el-main>

      <!-- 底部 -->
      <el-footer class="footer">
        <p>&copy; 2024 转盘抽奖系统. All rights reserved.</p>
      </el-footer>
    </el-container>
  </div>
</template>

<script setup>
import { useUserStore } from './stores/user'
import { ElMessage } from 'element-plus'

const userStore = useUserStore()

const logout = () => {
  userStore.logout()
  ElMessage.success('退出成功')
}
</script>

<style scoped>
#app {
  min-height: 100vh;
}

.header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 0;
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.logo h2 {
  color: white;
  margin: 0;
  font-size: 24px;
}

.nav-menu {
  flex: 1;
  display: flex;
  justify-content: center;
}

.user-info {
  display: flex;
  align-items: center;
}

.user-actions {
  display: flex;
  align-items: center;
  gap: 15px;
}

.username {
  color: white;
  font-weight: 500;
}

.auth-buttons {
  display: flex;
  gap: 10px;
}

.main-content {
  min-height: calc(100vh - 120px);
  background-color: #f5f5f5;
  padding: 20px;
}

.footer {
  background-color: #2c3e50;
  color: white;
  text-align: center;
  padding: 20px;
}

.footer p {
  margin: 0;
}

/* 全局样式 */
:global(body) {
  margin: 0;
  font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '微软雅黑', Arial, sans-serif;
}

:global(.el-menu--horizontal > .el-menu-item) {
  border-bottom: none !important;
}
</style>